package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行DML语句-INSERT
 */
public class JDBCDemo2 {
    public static void main(String[] args) throws Exception {
        //需求：向userinfo表中添加一条记录
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "192045");
        Statement state = conn.createStatement();
        String sql = "INSERT INTO userinfo (username,password,nickname,age) " +
                     "VALUES ('张三','123456','三儿',18)";

        int num = state.executeUpdate(sql);
        System.out.println("插入了" + num + "行数据");

        conn.close();
    }
}
